﻿Public Class ConfigRV
    Inherits System.Web.UI.Page

    Private dt As DataTable
    Private Property DataSource As Data.DataTable
        Get
            Return dt
        End Get
        Set(ByVal value As Data.DataTable)
            dt = value
        End Set
    End Property

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSearch.Click
        Dim info As Entity.RVItem = New Entity.RVItem
        info.calculate_rv_name = txtRVName.Text.Trim
        If StartDateFrom.Text <> "" Then info.rv_start_date = Common.UtilityDateTime.ConvertDate(Me.StartDateFrom.Text).Value.AddYears(-543)
        If StartDateTo.Text <> "" Then info.rv_start_date_to = Common.UtilityDateTime.ConvertDate(Me.StartDateTo.Text).Value.AddYears(-543)
        If EndDateFrom.Text <> "" Then info.rv_end_date = Common.UtilityDateTime.ConvertDate(Me.EndDateFrom.Text).Value.AddYears(-543)
        If EndDateTo.Text <> "" Then info.rv_end_date_to = Common.UtilityDateTime.ConvertDate(Me.EndDateTo.Text).Value.AddYears(-543)
        DataSource = BL.Configuration.GetRV(info)
        Bind(0)
    End Sub

    Private Sub Bind(ByVal pageIndex As Integer)
        Me.gvList.DataSource = DataSource
        Me.gvList.PageIndex = pageIndex
        Me.gvList.DataBind()
    End Sub

    Protected Sub btnReset_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnReset.Click
        Response.Redirect("ConfigRV.aspx", False)
    End Sub

    Private Sub gvList_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvList.PageIndexChanging
        Bind(e.NewPageIndex)
    End Sub

    Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAdd.Click
        Me.Response.Redirect("~/ConfigRVDetail.aspx?action=ADD", False)
    End Sub

    Protected Sub gvList_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles gvList.SelectedIndexChanged
        Try
            'GlobalApp.DataSourceEditOfficer = BL.Officer.LoadProfile(Me.gvList.SelectedValue)
            Response.Redirect("~/ConfigRVDetail.aspx?action=EDIT&infoid=" & Me.gvList.SelectedValue, False)
        Catch ex As Exception
            Me.Master.Alert("ไม่สามารถดึงข้อมูลที่ท่านต้องการได้")
            Common.LogError.AddLogException(ex)
        End Try
    End Sub
End Class